package teamdamn.view;

import javax.swing.JPanel;
import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.LayoutStyle.ComponentPlacement;
import javax.swing.JButton;

import java.awt.GridBagLayout;
import java.awt.GridBagConstraints;
import java.awt.Insets;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.BorderLayout;
import javax.swing.border.LineBorder;
import java.awt.Color;

/**
 * This panel is for the Analyst Functionality
 * @author kjudoy
 */
@SuppressWarnings("serial")
public class AnalystPanel extends JPanel {
	
	private SearchPanel mySearchPanel;	
	private RFPPanel myRFPPanel;	
	
	private JPanel panelAnalystCurrent;
	private JButton btnToRFP;
	private JButton btnToSearch;
	
	/**
	 * Default Constructor of Analyst Panel
	 * @edited joelhun
	 */
	public AnalystPanel(SearchPanel theSearchPanel) {	
		mySearchPanel = theSearchPanel;
		buildAnalystPanel() ;
	}
	
	/**
	 * This method build the GUI of this panel
	 * @author kjudoy
	 */
	private void buildAnalystPanel() {
		JPanel panelAnalystMenu = new JPanel();
		
		panelAnalystCurrent = new JPanel();
		panelAnalystCurrent.setBorder(new LineBorder(new Color(0, 0, 0)));
		GroupLayout groupLayout = new GroupLayout(this);
		groupLayout.setHorizontalGroup(
			groupLayout.createParallelGroup(Alignment.TRAILING)
				.addGroup(Alignment.LEADING, groupLayout.createSequentialGroup()
					.addContainerGap()
					.addComponent(panelAnalystMenu, GroupLayout.PREFERRED_SIZE, 89, GroupLayout.PREFERRED_SIZE)
					.addPreferredGap(ComponentPlacement.RELATED)
					.addComponent(panelAnalystCurrent, GroupLayout.DEFAULT_SIZE, 345, Short.MAX_VALUE))
		);
		groupLayout.setVerticalGroup(
			groupLayout.createParallelGroup(Alignment.LEADING)
				.addGroup(groupLayout.createSequentialGroup()
					.addGap(11)
					.addComponent(panelAnalystMenu, GroupLayout.DEFAULT_SIZE, 278, Short.MAX_VALUE)
					.addGap(11))
				.addComponent(panelAnalystCurrent, GroupLayout.DEFAULT_SIZE, 300, Short.MAX_VALUE)
		);
		panelAnalystCurrent.setLayout(new BorderLayout(0, 0));
		GridBagLayout gbl_panelAnalystMenu = new GridBagLayout();
		gbl_panelAnalystMenu.columnWidths = new int[]{0, 0};
		gbl_panelAnalystMenu.rowHeights = new int[]{20, 20, 0, 0, 20, 0};
		gbl_panelAnalystMenu.columnWeights = new double[]{1.0, Double.MIN_VALUE};
		gbl_panelAnalystMenu.rowWeights = new double[]{0.0, 0.0, 0.0, 0.0, 1.0, Double.MIN_VALUE};
		panelAnalystMenu.setLayout(gbl_panelAnalystMenu);
		
		btnToRFP = new JButton("RFP List");
		
				GridBagConstraints gbc_btnToRFP = new GridBagConstraints();
				gbc_btnToRFP.fill = GridBagConstraints.HORIZONTAL;
				gbc_btnToRFP.insets = new Insets(0, 0, 5, 0);
				gbc_btnToRFP.gridx = 0;
				gbc_btnToRFP.gridy = 2;
				panelAnalystMenu.add(btnToRFP, gbc_btnToRFP);
				
				
					//Button Action
					btnToRFP.addActionListener(new ActionListener() {
						public void actionPerformed(ActionEvent arg0) {
							panelToRFP();
						}
					});
		
		btnToSearch = new JButton("Search");
		
				GridBagConstraints gbc_btnToSearch = new GridBagConstraints();
				gbc_btnToSearch.fill = GridBagConstraints.HORIZONTAL;
				gbc_btnToSearch.insets = new Insets(0, 0, 5, 0);
				gbc_btnToSearch.gridx = 0;
				gbc_btnToSearch.gridy = 3;
				panelAnalystMenu.add(btnToSearch, gbc_btnToSearch);
				
				btnToSearch.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent e) {
						panelToSearch();
					}
				});
		setLayout(groupLayout);
	}
	
	/**
	 * This method for swaps the current panel to RFP Panel
	 * @author kjudoy
	 * @edited joelhun
	 */
	public void panelToRFP() {
		myRFPPanel = new RFPPanel(this);
		if (panelAnalystCurrent.getComponentCount() != 0)
			panelAnalystCurrent.remove(panelAnalystCurrent.getComponent(0));
		panelAnalystCurrent.add(myRFPPanel);
		panelAnalystCurrent.revalidate();
		panelAnalystCurrent.repaint();
	}
	
	/**
	 * This method for swaps the current panel to Search Panel
	 * @author kjudoy
	 * @edited joelhun
	 */
	public void panelToSearch() {
		if (panelAnalystCurrent.getComponentCount() != 0)
			panelAnalystCurrent.remove(panelAnalystCurrent.getComponent(0));
		panelAnalystCurrent.add(mySearchPanel);
		panelAnalystCurrent.revalidate();
		panelAnalystCurrent.repaint();
	}
}
